package kpi;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class MessageMg implements ServletContextListener  {
	private Timer timer = null;

  public void contextInitialized(ServletContextEvent event) {
     timer = new Timer(true);
    //设置任务计划，启动和间隔时间
     //timer.schedule(new MyTask(), 0, 1000*60*60*24*7*4);
     timer.schedule(new MyTask(), 0, 1000);
   }

  public void contextDestroyed(ServletContextEvent event) {
     timer.cancel();
   }

}
class MyTask extends TimerTask {

  public void run() {
    System.out.println("this is a task!!");
   }

}
